package com.service.socket.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.service.dao.mapper.TradingSpotTradesMapper;
import com.service.dao.model.TradingSpotTrades;
import com.service.match.common.entity.SpotTradeVo;
import com.service.socket.service.TradingSpotTradesService;
import com.service.utility.modelmapper.ModelMapperUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;


@Service("tradingSpotTradesService")
public class TradingSpotTradesServiceImpl extends ServiceImpl<TradingSpotTradesMapper, TradingSpotTrades> implements TradingSpotTradesService {

    @Override
    public TradingSpotTrades getLastTrade(String symbol) {
        return getOne(new QueryWrapper<TradingSpotTrades>().lambda()
                .eq(TradingSpotTrades::getSymbol, symbol).orderByDesc(TradingSpotTrades::getId).last("limit 1"));
    }

    @Override
    public SpotTradeVo getLastTradeVo(String symbol) {
        TradingSpotTrades spotTrades = getLastTrade(symbol);
        return ObjectUtils.isEmpty(spotTrades) ? null : ModelMapperUtil.map(spotTrades, SpotTradeVo.class);
    }


}
